package com.yyy.djk.dropdownmenu;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yyydjk.library.ITabView;

/**
 * Created by xujl on 2017/12/14.
 */

public class CustomTab extends ImageView implements ITabView<String> {
    private boolean isChecked;
    public CustomTab (Context context) {
        super(context);
        init();
    }

    public CustomTab (Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomTab (Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public CustomTab (Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init () {
        setImageResource(R.mipmap.ic_action_uncheck);
        setScaleType(ScaleType.CENTER);
        setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
    }

    @Override
    public void setTabContent (String data) {

    }

    @Override
    public void setClickListener (OnClickListener onClickListener) {
        setOnClickListener(onClickListener);
    }

    @Override
    public void checked () {
        if(isChecked){
            setImageResource(R.mipmap.ic_action_uncheck);
        }else{
            setImageResource(R.mipmap.ic_action_checked);
        }
        isChecked = !isChecked;
    }

    @Override
    public void unChecked () {
        isChecked = false;
        setImageResource(R.mipmap.ic_action_uncheck);
    }
}
